$(function () {
  const form = layui.form;
  const layer = layui.layer;
  

  // 正则
  form.verify({
    pwd: [/^[\S]{6,12}$/, "密码必须6到12位,且不能出现空格"],
    code: function (value) {
      const pwd = $("#oldPwd").val();
      if (pwd === value) {
        return "不能与原密码相同！";
      }
    },
    Retype: function (value) {
      const pwd = $("#new_code").val();
      if (pwd !== value) {
        return "两次密码不相同！";
      }
    },
  });
   
 // 重置密码功能
  postReset()
  function postReset() {
    $("#formReset").on("submit", function (e) {
      e.preventDefault();
      $.ajax({
        method: "post",
        url: "/my/updatepwd",
        data: $(this).serialize(),
        success: function (res) {
          console.log(res);
          if(res.status !== 0){
            return layer.msg(res.message)
          }
          layer.msg(res.message)
          // 重置表单
          // $('#btnout').click()

          localStorage.removeItem('token')
          top.location.href = '/login.html'
          // window.parent.location.href = '/login.html'
        },
      });
    });
  }
});
